import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'
export const USER_SET = "USER_SET";
export const LIST_SET = "LIST_SET";
export const OTHER_SET = "OTHER_SET";
var storeInfo = {
    strict: true,
    state: {
        userInfo: {
            lastRoute: undefined, //记录上一个页面的路由，用以选择地址后回退
        },
        list: {},
        other: {
            newDetail: null, //存储商品详情
        }
    },
    mutations: {
        [USER_SET](state, user) {
            state.userInfo = Object.assign(state.userInfo, user);
        },
        [LIST_SET](state, list) {
            state.list = Object.assign(state.list, list);
        },
        [OTHER_SET](state, other) {
            state.other = Object.assign(state.other, other);
        }
    },
    plugins: [
        createPersistedState({
            storage: {
                getItem: key => wx.getStorageSync(key),
                setItem: (key, value) => wx.setStorageSync(key, value),
                removeItem: key => {}
            }
        })
    ]
}
Vue.use(Vuex)

export default new Vuex.Store(storeInfo)